package com.tianhua.javs.client.model;


import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:属性模型
 * date: 2021/6/28
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Data
public class FieldModel {
    /**
     * 属性名称
     */
    private String fieldName;
    /**
     * 访问权限
     */
    private String visibility;

    /**
     * 属性描述
     */
    private String desc;


    /**
     * 属性类型
     */
    private String fieldType;

    /**
     * 属性简单名称
     */
    private String fieldSimpleName;

    /**
     * plantUMl类图的原始数据
     */
    private String originFieldStr;

    /**
     * 所属类名
     */
    private String className;

    /**
     * 注解
     */
    private String annotation;


    /**
     * 变量赋值情况
     */
    private String initValue;

    public FieldModel(){}

    /**
     * 属性需要依赖的包
     */
    private List<String> packageList = new ArrayList<>();

    public void buildFieldDetail(){
        if(this.getFieldName().contains(" ")){
            String [] fieldArr = this.getFieldName().split(" ");
            this.setFieldType(fieldArr[0]);
            this.setFieldSimpleName(fieldArr[1]);
        }
    }

    public String getGetterMethod(){
        String fieldSimpleName = this.getFieldSimpleName();
        return "get" + fieldSimpleName.substring(0,1).toUpperCase() + fieldSimpleName.substring(1) + "()";
    }

    public String getGetterMethodSimple(){
        return getGetterMethod().replace("()","");
    }


    public String getSetterMethod(){
        String fieldSimpleName = this.getFieldSimpleName();
        return "set" + fieldSimpleName.substring(0,1).toUpperCase() + fieldSimpleName.substring(1) + "()";
    }

    public void addPackageList(List<String> packageList){
        this.packageList.addAll(packageList);
    }
}
